package com.zjt.smart.api.server;

import com.zjt.smart.util.SecurityUtil;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author zhengjianting
 * @time 2017/8/25 0025 上午 11:19
 */

public class Cookies {
    HashMap<String,String> cookies;

    public Cookies() {
        cookies = new HashMap<>();
    }

    public void setCookies(HashMap<String, String> cookies) {
        this.cookies = cookies;
    }

    public void addCookie(String key ,String value){
        cookies.put(key,value);
    }

    @Override
    public String toString() {
        Set<Map.Entry<String, String>> entry =cookies.entrySet();
        Iterator<Map.Entry<String, String>> keys = entry.iterator();
        String val = "", split = "";
        while (keys.hasNext()) {
            Map.Entry<String, String> item = keys.next();
            val += split + SecurityUtil.escape(item.getKey()) + "=" + SecurityUtil.escape(item.getValue());
            split = ";";
        }
        return val;
    }
}
